package com.hl.sfzy.controller;



import com.hl.sfzy.entity.MyTest;
import com.hl.sfzy.service.MyTestService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mytest")
public class MyTestController {

    @Autowired
    private MyTestService myTestService;

    @PostMapping("/add")
    public R insert(@RequestBody MyTest myTest){
            int result = myTestService.add(myTest);
            if (result > 0) {
                return R.ok("插入成功");
            }else {
                return R.error("插入失败");
            }
    }
    @GetMapping("/{id}")
    public R getMyTestById(@PathVariable Long id){
        return R.ok(myTestService.findById(id));
    }
    @PutMapping("/edit")
    public R updateMyTest(@RequestBody MyTest myTest){
        return R.ok(myTestService.edit(myTest));
    }
    @DeleteMapping("/{id}")
    public R deleteMyTest(@PathVariable Long id){
        return R.ok(myTestService.remove(id));
    }
    @GetMapping("/findAll")
    public R getAllMyTests(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            MyTest myTest
    ){
        return R.ok(myTestService.findAll(pageNum, pageSize, myTest));
    }

}
